/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "course_thread")
@NamedQueries({@NamedQuery(name = "CourseThread.findBySubject", query = "SELECT c FROM CourseThread c WHERE c.courseThreadPK.subject = :subject"), @NamedQuery(name = "CourseThread.findByCode", query = "SELECT c FROM CourseThread c WHERE c.courseThreadPK.code = :code"), @NamedQuery(name = "CourseThread.findBySection", query = "SELECT c FROM CourseThread c WHERE c.courseThreadPK.section = :section"), @NamedQuery(name = "CourseThread.findByName", query = "SELECT c FROM CourseThread c WHERE c.courseThreadPK.name = :name"), @NamedQuery(name = "CourseThread.findByPost", query = "SELECT c FROM CourseThread c WHERE c.courseThreadPK.post = :post")})
public class CourseThread implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CourseThreadPK courseThreadPK;
    @JoinColumns({@JoinColumn(name = "subject", referencedColumnName = "subject", insertable = false, updatable = false), @JoinColumn(name = "code", referencedColumnName = "code", insertable = false, updatable = false), @JoinColumn(name = "section", referencedColumnName = "section", insertable = false, updatable = false)})
    @ManyToOne
    private Course course;

    public CourseThread() {
    }

    public CourseThread(CourseThreadPK courseThreadPK) {
        this.courseThreadPK = courseThreadPK;
    }

    public CourseThread(String subject, String code, String section, String name, int post) {
        this.courseThreadPK = new CourseThreadPK(subject, code, section, name, post);
    }

    public CourseThreadPK getCourseThreadPK() {
        return courseThreadPK;
    }

    public void setCourseThreadPK(CourseThreadPK courseThreadPK) {
        this.courseThreadPK = courseThreadPK;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (courseThreadPK != null ? courseThreadPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CourseThread)) {
            return false;
        }
        CourseThread other = (CourseThread) object;
        if ((this.courseThreadPK == null && other.courseThreadPK != null) || (this.courseThreadPK != null && !this.courseThreadPK.equals(other.courseThreadPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.CourseThread[courseThreadPK=" + courseThreadPK + "]";
    }

}
